package cn.edu.hqu.cst.android.wzc.myapplication;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Button;
import android.widget.FrameLayout;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Timer;
import java.util.TimerTask;

public class UC3 extends AppCompatActivity {
    FrameLayout frame;
    Handler handler = new Handler()
    {
        int i = 0;
        public void handleMessage(Message msg) {
            if(msg.what == 0x123)
            {
                i++;
                change(i % 5 );
            }
            super.handleMessage(msg);
        }
    };

    void change(int i)
    {
        Drawable a = getResources().getDrawable(R.drawable.p_1);
        Drawable b = getResources().getDrawable(R.drawable.p_2);
        Drawable c = getResources().getDrawable(R.drawable.p_2);
        Drawable d = getResources().getDrawable(R.drawable.p_4);
        Drawable e = getResources().getDrawable(R.drawable.p_5);
        switch(i)
        {
            case 0:
                frame.setForeground(a);
                break;
            case 1:
                frame.setForeground(b);
                break;
            case 2:
                frame.setForeground(c);
                break;
            case 3:
                frame.setForeground(d);
                break;
            case 4:
                frame.setForeground(e);
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc3);

        frame = (FrameLayout) findViewById(R.id.frame);
        Button bt1=findViewById(R.id.button15);
        bt1.setOnClickListener(v -> finish());

        new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                handler.sendEmptyMessage(0x123);
            }
        }, 0,250);
    }
}